from collections import Counter

from sklearn.datasets import load_iris
from sklearn.model_selection import LeaveOneOut, LeavePOut


def test01():
    # 加载数据
    x, y = load_iris(return_X_y=True)
    print('随机类别划分：', Counter(y))
    #留一法
    splitter = LeaveOneOut()
    for train, test in splitter.split(x, y):
        print('训练集:',len(train),'测试集:',len(test), test)
    #留P法
    splitter = LeavePOut(p=3)
    for train, test in splitter.split(x, y):
        print('训练集:', len(train), '测试集:', len(test), test)
if __name__ == '__main__':
    test01()